<template>
    <div>
        <table class="table">
            <tbody>
                <tr>
                    <td>标题</td>
                    <td>
                        <input type="text" v-model="can.til">
                    </td>
                </tr>
                <tr>
                    <td>类型</td>
                    <td>
                        <select v-model="can.tid">
                            <option :value="0">=请选择=</option>
                            <option v-for="x in showdata" :value="x.tid">{{x.tname}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="add">
                        <input type="button" value="查询" @click="show">
                        <a href="https://localhost:7194/api/Anno/UpdownExcel">导出公告信息</a>
                    </td>
                </tr>
            </tbody>
        </table>
        <table class="table">
            <thead class="table">
                <tr>
                    <td>标题</td>
                    <td>内容</td>
                    <td>发布时间</td>
                    <td>状态</td>
                    <td>类型</td>
                </tr>
            </thead>
            <tbody class="table">
                <tr v-for="a in data">
                    <td>{{a.title}}</td>
                    <td>{{ a.content }}</td>
                    <td>{{ moment(a.publishTime).format("YYYY-MM-DD  HH:mm:ss") }}</td>
                    <td>{{a.status?"启用":"禁用"}}</td>
                    <td>{{ a.tname }}</td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import moment from 'moment';
import { useRouter } from 'vue-router';
onMounted(() => {
    showdd();
    show();
})
const showdata=ref([{
     "tid": 0,
    "tname": ""
}])

const showdd=()=>{
    axios.get("https://localhost:7194/api/Anno/GetTypes").then(res=>{
        showdata.value=res.data;
    })
}
const can=ref({
    til:'',
    tid:0
})

const data=ref([{
    "tid": 0,
    "tname": "",
    "aid": 0,
    "title": "",
    "content": "",
    "publishTime": "",
    "status": true
}])

const show=()=>{
    axios.get("https://localhost:7194/api/Anno/GetAnouncement",{params:can.value}).then(res=>{
        data.value=res.data;
    })
}


const router=useRouter();
const add=()=>{
    router.push({
        path:'/NoAddView'
    })
}
</script>

<style scoped>

</style>